﻿package igz.fleaxy.net {
	import igz.fleaxy.events.CommEvent;
	import igz.fleaxy.pattern.AbstractFactory;
	
	/**
	 * @author Intelygenz | www.intelygenz.com
	 * 
	 * Manager de mensajes DTO sobre el COM
	 */
	public class CommErrorManager extends AbstractFactory {

		static public var $JSON_BLOCK_NAME : String = "error";

		protected var _ErrorDto:CommErrorDto;
		public function get $ErrorDto() : CommErrorDto {
			return _ErrorDto;
		}

		public function CommErrorManager() {
			super(CommErrorDto);
		}

		public function $LoadError(p_commEvent:CommEvent) : void {
			_ErrorDto = null;
			switch ( p_commEvent.$CommResponseType ) {
				case CommResponseType.$JSON :
					var rootTag : String = "";
					for ( rootTag in p_commEvent.$ResponseJSON ) { break; }
					if ( p_commEvent.$ResponseJSON[rootTag] != null && p_commEvent.$ResponseJSON[rootTag].hasOwnProperty( $JSON_BLOCK_NAME ) ) {
						$LoadFromJSON(p_commEvent.$ResponseJSON, $JSON_BLOCK_NAME);
					}
					break;
			}
			if ( _Dtos.length > 0 ) {
				_ErrorDto = _Dtos[0] as CommErrorDto;
			}
		}

	}

}